package org.iblink.gui.swing.frames;

import java.awt.BorderLayout;
import java.awt.Color;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JRootPane;
import javax.swing.JWindow;

/**
 * Class for displaying an image while loading.
 * 
 * @author tpares
 *
 */
public class LoadWindow extends JWindow {

  /**
   * Generated serial version UID
   */
  private static final long serialVersionUID = 1395466054676970178L;

  /**
   * Loading window constructor
   */
  public LoadWindow(){
    super();
    
    build();
  }
  
  /**
   * Builds the loading window
   */
  private void build(){
    setSize(300, 200);
    setLocationRelativeTo(null);
    
    // Display image
    setRootPane(buildContent());
  }
  
  /**
   * Build root pane content
   * 
   * @return the root pane
   */
  private JRootPane buildContent() {
    JRootPane panel = new JRootPane();
    
    panel.setLayout(new BorderLayout());
    
    JLabel img;
    URL imgURL = getClass().getClassLoader().getResource("images/iblink_logo.jpg");
    if (imgURL != null) {
      img = new JLabel(new ImageIcon(imgURL));
    } else {
      img = new JLabel();
    }
    panel.add(img);
    
    panel.add(new JLabel("Please wait while loading...", JLabel.CENTER), BorderLayout.SOUTH);
    
    panel.setBackground(Color.white);
    
    return panel;
  }
}
